/**
 * GameStorage
 * @Author Ace.c
 * @Create 2016-12-12 19:36
 */
class GameStorage {

    //----------------------用户
    //微信code
    static wx_code: string = "wx_code";
    //用户code
    static code: string = 'code';
    //用户uid
    static uid: string = 'uid';
    //同意协议内容
    static agreed: string = 'agreed';
    //用户每日首次登录
    static first: string = 'first';

    //----------------------游戏
    //风格
    static desktopColor: string = "desktopColor";
    //颜色
    static paiColor: string = "paiColor";
    //音乐
    static music: string = "music";
    //音乐音量
    static musicVolume: string = "musicVolume";
    //音效
    static sound: string = "sound";
    //音效音量
    static soundVolume: string = "soundVolume";

    //----------------------房间
    //房间类型
    static roomType: string = "roomType";
    //房间模式
    static round: string = "round";
    //人数
    static seat: string = "seat";
    //支付
    static cost: string = "cost";
    //封顶
    static seal: string = "seal";
    //规则
    static rule: string = "rule";

    static init() {
        if (!GameStorage.getData(GameStorage.desktopColor)) GameStorage.setData(GameStorage.desktopColor, 0);
        if (!GameStorage.getData(GameStorage.paiColor)) GameStorage.setData(GameStorage.paiColor, 0);
        if (!GameStorage.getData(GameStorage.music)) GameStorage.setData(GameStorage.music, 1);
        if (!GameStorage.getData(GameStorage.sound)) GameStorage.setData(GameStorage.sound, 1);
        if (!GameStorage.getData(GameStorage.musicVolume)) GameStorage.setData(GameStorage.musicVolume, 0.2);
        if (!GameStorage.getData(GameStorage.soundVolume)) GameStorage.setData(GameStorage.soundVolume, 0.5);
    }

    //读取
    static getData(key: string) {
        return egret.localStorage.getItem(this.keyTitle + key);
    }

    //储存
    static setData(key: string, value: any): void {
        egret.localStorage.setItem(this.keyTitle + key, value);
    }

    //删除
    static delData(key: string) {
        egret.localStorage.removeItem(this.keyTitle + key);
    }

    //游戏存储key
    private static get keyTitle(): string {
        return "mqkj@mj" + "-" + GameConfig.gameType + "-" + GameConfig.version_cookies + "-";
    }
}